package com.lesama.test;

import com.lesama.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class ArrayListTest3 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            System.out.println("请输入第" + (i + 1) + "个学生的姓名和年龄");
            addStudent(list);
        }
        printStudent(list);
    }
    public static void printStudent(ArrayList<Student> list) {
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).toString());
        }
    }
    public static void addStudent(ArrayList<Student> list) {
        Scanner sc = new Scanner(System.in);
        String name = sc.next();
        int age = sc.nextInt();
        Student stu = new Student(name, age);
        list.add(stu);
    }
}
